<template>
    <div class="container">
        <CustomNav custom-title="测试详情" />
        <div class="content">
            <div class="content-top">
                <van-image class="img-icon mt-30" fit="cover" position="left" :src="detailData.poster" />
                <div class="title mt-20">{{ detailData.name }}</div>
                <div class="title-sub mt-10">{{ detailData.advertise_title }}</div>
                <div class="btn-click btn-start btn-blue btn-six-edge mt-20" @click="switchPopup">开始测试</div>
            </div>
            <div class="content-bottom">
                <div class="norm-box">
                    <div class="norm-item">
                        <div>
                            <span>{{ detailData.item_count }}</span>
                            题
                        </div>
                        <div class="mt-10">题目数量</div>
                    </div>
                    <div class="norm-item">
                        <div>
                            <span>{{ detailData.exam_total_time_custom }}</span>
                            分钟
                        </div>
                        <div class="mt-10">预计用时</div>
                    </div>
                    <div class="norm-item">
                        <div>
                            <span>{{ detailData.evaluate_num }}</span>
                            万
                        </div>
                        <div class="mt-10">测评次数</div>
                    </div>
                </div>
                <div class="information">
                    <div class="info-title">评测须知</div>
                    <div class="info-desc" v-html="detailData.exam_tips"></div>
                </div>
                <div class="information" v-if="detailData.introduce">
                    <div class="info-title">评测介绍</div>
                    <div class="info-desc" v-html="detailData.introduce"></div>
                </div>
                <div class="mt-10">
                    <van-image class="img-detail" v-for="detailImage in detailData.introduce_images" fit="cover"
                        position="left" :src="detailImage" />
                </div>
            </div>
        </div>
        <PopupBottom ref="PopupBottomRef"></PopupBottom>
    </div>
</template>

<script lang="ts" setup>
import { Ref, onActivated, ref, onDeactivated } from 'vue';
import { useRoute } from 'vue-router';
import PopupBottom from '@/pages/components/PopupBottom/index.vue'
import CustomNav from '@/pages/components/CustomNav/index.vue'
import { TestItemDetailProps } from '../type';
import { getExamsDetailById } from '../../api/Home';
import { utils } from '../../utils';
const route = useRoute()
const PopupBottomRef: Ref<any> = ref(null)
const switchPopup = () => {
    PopupBottomRef.value?.switchShow(true, route.params.id)
}
const detailData = ref<TestItemDetailProps>({})

onActivated(async () => {
    if (route.params.id !== void 0) {
        const { code, data } = await getExamsDetailById(`${route.params.id}`)
        if (`${code}` === '0') {
            const detailDataRomate = await utils.getJson(`${data.detail_url}`)
            detailData.value = { ...detailDataRomate, evaluate_num: ((data.evaluate_num || 15000) / 10000).toFixed(1), exam_total_time_custom: Math.round((detailDataRomate.item_count * 10) / 60) }
        }
    }
})
onDeactivated(() => {
    detailData.value = {}
})
</script>

<style lang="scss" scoped>
.container {
    height: 100vh;
    overflow: hidden;
    background-color: $color_bg_grey;
    display: flex;
    flex-direction: column;

    .content {
        flex: 1;
        overflow-y: auto;

        .content-top {
            width: 100%;
            height: 360px;
            background: linear-gradient(180deg, #0A092A 0%, #34186C 100%);
            display: flex;
            flex-direction: column;
            align-items: center;

            .img-icon {
                width: 197px;
                height: 100px;
                border-radius: 6px;
                overflow: hidden;
            }

            .title {
                font-size: 18px;
                color: $color_white;
            }

            .title-sub {
                width: 80%;
                line-height: 16px;
                text-align: center;
                font-size: 12px;
                color: $color_sub_title;
            }

            .btn-start {
                width: 238px;
            }
        }

        .content-bottom {
            width: 100%;
            background-color: $color_bg_grey;
            border-top-right-radius: 10px;
            border-top-left-radius: 10px;
            margin-top: -50px;
            padding: 15px;
            padding-bottom: 30px;

            .norm-box {
                display: flex;
                justify-content: space-between;
                align-items: center;

                .norm-item {
                    width: 109px;
                    height: 76px;
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    align-items: center;
                    background-color: $color_white;
                    border-radius: 6px;

                    &>div {
                        color: $color_text_grey;
                        font-size: 14px;

                        &>span {
                            font-size: 14px;
                            color: #5870D8;
                        }
                    }
                }
            }

            .information {
                padding-top: 20px;

                .info-title {
                    font-size: 14px;
                    color: #262626;
                    font-weight: bold;
                }

                .info-desc {
                    background-color: $color_white;
                    font-size: 13px;
                    color: $color_text_grey;
                    letter-spacing: 0.02em;
                    padding: 10px 15px;
                    border-radius: 6px;
                    margin-top: 10px;
                    line-height: 24px;
                    text-align: justify;
                }
            }

            .img-detail {
                width: 100%;
            }
        }
    }
}
</style>